package com.example.test001.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

@RestController
public class SessionController {


    @GetMapping("/session/id")
    public Object getSession(HttpServletRequest request ){
        return request.getSession().getId();
    }

    @GetMapping("/session/key")
    public Object getSessionKey(HttpServletRequest request ){
        Enumeration <String > keys  =    request.getSession().getAttributeNames();
        List<Object> list = new ArrayList<>();
        while (keys.hasMoreElements()){
            list.add( request.getSession().getAttribute(keys.nextElement()));
        }
        return list;
    }



    @GetMapping("/session/value")
    public Object getSessionValue(HttpServletRequest request ){
        Enumeration <String > keys = request.getSession().getAttributeNames();

        List<Object> list = new ArrayList<>();
        while (keys.hasMoreElements()){
            list.add( request.getSession().getAttribute(keys.nextElement()));
        }



        return list;
    }


}
